home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
uemlsrc.arc
/
random.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-08-24
|
17KB
|
562 lines
/*
* This file contains the
* command processing functions for
* a number of random commands. There is
* no functional grouping here, for
* sure.
*/
#include <stdio.h>
#include "ed.h"
int tabsize; /* Tab size (0: use real tabs) */
char fillprefix[80]; /* rather large but who knows */
int yankcflag = FALSE;
/*
* Set fill column to n. The fill column is global, but the individual
* buffer can be filled or not depending on its mode.
*/
setfillcol(f, n)
register int f, n;
{
register WINDOW *wp;
register BUFFER *bp;
fillcol = (n == 1) ? (getccol(FALSE) + 1) : n;
n = fillcol;
wp = wheadp;
bp = curwp->w_bufp;
if (n > 1)
{
bp->b_bmode |= BMWRAP;
bp->b_bmode &= ~BMNWRAP;
}
else
{
bp->b_bmode |= BMNWRAP;
bp->b_bmode &= ~BMWRAP;
}
upmode();
mlwrite("Fill column is %d", n);
return(TRUE);
}
/*
* Set indent column to n or set fill prefix to string.
*/
setindcol(f, n)
register int f, n;
{
short curdo; /* current dot offset */
register short tdo; /* moveable dot offset */
register short i;
char tstring[80]; /* temporary store for prefix string */
i = 0;
tdo = 0;
curdo = curwp->w_doto;
if (n>1) /* called with argument, so just set the indcol */
{
if (n >= 80)
n=79;
indcol = n;
/* copy the correct number of tabs and spaces into string */
if ((tdo=indcol/8)!=0)
while (tdo--)
tstring[i++] = '\t';
if ((tdo=indcol%8)!=0)
while (tdo--)
tstring[i++] = ' ';
tstring[i] = '\0';
strncpy(fillprefix,tstring,79);
mlwrite("Indent column is %d", indcol);
return(TRUE);
}
indcol = getccol(FALSE) +1;
/* now fabricate fill prefix string */
do {
curwp->w_doto = tdo;
tstring[tdo] = lgetc(curwp->w_dotp,tdo);
} while (++tdo < curdo && tdo < 80);
tstring[curdo] = '\0';
curwp->w_doto = curdo;
strncpy(fillprefix,tstring,79);
mlwrite("Fill prefix is '%s'",fillprefix);
return(TRUE);
}
/*
* Display the current position of the cursor,
* in origin 1 X-Y coordinates, the character that is
* under the cursor (in hex), and the fraction of the
* text that is before the cursor. The displayed column
* is not the current column, but the column that would
* be used on an infinite width display. Normally this
* is bound to "C-X =".
*/
showcpos(f,n)
int f, n;
{
register LINE *clp;
register long nch;
register long nbc;
register long nmc;
register int cbo;
register int cac;
register int page;
register int col;
register int i;
register int row;
register long tl1;
float ratio, tf1, tf2;
char buf[12], *ftoa();
i = 0;
clp = lforw(curbp->b_linep); /* Grovel the data. */
cbo = 0;
nch = 0;
for (;;) {
if (clp==curwp->w_markp && cbo==curwp->w_marko)
nmc = nch;
if (clp==curwp->w_dotp && cbo==curwp->w_doto) {
nbc = nch;
row = i;
if (cbo == llength(clp))
cac = '\n';
else
cac = lgetc(clp, cbo);
}
if (cbo == llength(clp)) {
if (clp == curbp->b_linep)
break;
clp = lforw(clp);
++i;
cbo = 0;
} else
++cbo;
++nch;
}
col = getccol(FALSE) + 1; /* Get real column. */
if (nch != 0L)
{
tl1 = nbc * 100L;
tf1 = (float)tl1;
tf2 = (float)nch;
ratio = tf1/tf2;
}
(void)ftoa(ratio,buf,4);
buf[strlen(buf)-2] = '\0'; /* fool precision error */
if (curwp->w_dotp == curbp->b_linep)
row = i;
page = row / pagelen + 1;
mlwrite("page:=%d col:=%d line:=%d CH:=0x%x mark:=%D point:=%D (%s%% of %D)",
page, col, row, cac, nmc, nbc, buf, nch);
return (TRUE);
}
/*
* Return current column. Stop at first non-blank given TRUE argument.
*/
getccol(bflg)
int bflg;
{
register int c, i, col;
col = 0;
for (i=0; i<curwp->w_doto; ++i) {
c = lgetc(curwp->w_dotp, i);
if (c!=' ' && c!='\t' && bflg)
break;
if (c == '\t')
col |= 0x07;
else if (c<0x20 || c==0x7F)
++col;
++col;
}
return(col);
}
/*
* Twiddle the two characters on either side of
* dot. If dot is at the end of the line twiddle the
* two characters before it. Return with an error if dot
* is at the beginning of line; it seems to be a bit
* pointless to make this work. This fixes up a very
* common typo with a single stroke. Normally bound
* to "C-T". This always works within a line, so
* "WFEDIT" is good enough.
*/
twiddle(f, n)
register int f, n;
{
register LINE *dotp;
register int doto;
register int cl;
register int cr;
dotp = curwp->w_dotp;
doto = curwp->w_doto;
if (doto==llength(dotp) && --doto<0)
return (FALSE);
cr = lgetc(dotp, doto);
if (--doto < 0)
return (FALSE);
cl = lgetc(dotp, doto);
lputc(dotp, doto+0, cr);
lputc(dotp, doto+1, cl);
lchange(WFEDIT);
return (TRUE);
}
/*
* Quote the next character, and
* insert it into the buffer. All the characters
* are taken literally, with the exception of the newline,
* which always has its line splitting meaning. The character
* is always read, even if it is inserted 0 times, for
* regularity. Bound to "M-Q" (for me) and "C-Q" (for Rich,
* and only on terminals that don't need XON-XOFF).
*/
quote(f, n)
register int f, n;
{
register int s;
register int c;
c = (*term.t_getchar)();
if (n < 0)
return (FALSE);
if (n == 0)
return (TRUE);
if (c == '\n') {
do {
s = lnewline();
} while (s==TRUE && --n);
return (s);
}
return (linsert(n, c));
}
/*
* Set tab size if given non-default argument (n <> 1). Otherwise, insert a
* tab into file. If given argument, n, of zero, change to true tabs.
* If n > 1, simulate tab stop every n-characters using spaces.
* This has to be done in this slightly funny way because the
* tab (in ASCII) has been turned into "C-I" (in 10
* bit code) already. Bound to "C-I".
*/
tab(f, n)
register int f, n;
{
if (n < 0)
return (FALSE);
if (n == 0 || n > 1) {
tabsize = n;
return(TRUE);
}
if (! tabsize)
return(linsert(1, '\t'));
return(linsert(tabsize - (getccol(FALSE) % tabsize), ' '));
}
/*
* Open up some blank space. The basic plan
* is to insert a bunch of newlines, and then back
* up over them. Everything is done by the subcommand
* processors. They even handle the looping. Normally
* this is bound to "C-O".
*/
openline(f, n)
register int f, n;
{
register int i;
register int s;
if (n < 0)
return